home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Disc to the Future 2
/
Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin
/
MAC
/
THINKC
/
TCL1
/
CTRACE2_
/
CLOGLIST.C
next >
Wrap
Text File
|
1990-12-10
|
2KB
|
82 lines
/*****
from CTRACE: A MESSAGE LOGGING CLASS
by William D. Cramer in Dr. Dobbs Journal #170, p. 44-55, 116-120.
*****/
/** CLogList.c -- Methods for a LogList object. **/
#include "CLogList.h" /* definitions for LogList class */
/** ILogList -- Initializes a LogList for the indicated number of entries. **/
void CLogList::ILogList
(
short records /* maximum number of entries */
)
{
CList::IList ();
maxRec = records;
}
/** Dispose -- Frees all records (and their handles) in the list **/
void CLogList::Dispose (void)
{
short
i; /* loop counter */
Handle
record; /* handle to list record */
while (GetNumItems() > 0)
{
record = (Handle)FirstItem();
Remove ((CObject*)record);
DisposHandle (record);
}
}
/** AddString -- Adds a string to LogList. **/
void CLogList::AddString
(
char *theString /* pointer to null-terminated string */
)
{
Handle
record; /* handle for a list entry */
if (strlen(theString)+1 < MAX_LOGREC_CHAR)
{
record = NewHandle (strlen(theString)+1);
strcpy (*record, theString);
}
else
{
record = NewHandle (MAX_LOGREC_CHAR);
strncpy (*record, theString, MAX_LOGREC_CHAR);
*record[MAX_LOGREC_CHAR-1] = NULL;
}
Append ((CObject*)record);
if (GetNumItems () > maxRec)
{
record = (Handle)FirstItem ();
Remove ((CObject*)record);
DisposHandle (record);
}
}
/** GetString -- Grabs requested entry and copies it to user's buffer. **/
void CLogList::GetString
(
short which, /* record number to return */
char *theString /* point to destination buffer */
)
{
Handle
record; /* handle for a list entry */
if ( (record=(Handle)NthItem(which)) != NULL)
strcpy (theString, *record);
else
theString[0] = 0;
}
/** GetMaxRecordCount -- Returns max.number of records available in LogList **/
short CLogList::GetMaxRecordCount (void)
{
return (maxRec);
}